<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<div class="ibox-content">
   <div class="social-feed-separated"  id="discuss-info">
          
   </div>
</div>
		
	<script>
	
	function serializeObject(obj, aoData) {
        var a = obj.serializeArray();
        $.each(a,
        function() {
            aoData[this.name] = this.value || ""
        });
        return aoData
    }
	
	var retrieveData=function(){
		var discussId ="${discussId}";
		$.ajax({  
			url:'${ctx}/discuss/infoData',  
			data:{"discussId":discussId},   
			type: 'POST',
				dataType:'json',  
				success:function(response){
					if(response.code==0){
						var data=response.data;
						var answers=data.answers;
						var discusses=data.discusses;
						var id=discusses.id;
			            
						var html = [];
						html.push('<div class="social-avatar" id="'+id+'-social-avatar-info">');
						html.push('<a href="">');
						html.push('<img class="feed-photo"  alt="image" src="'+discusses.createHeadImg+'">');
						html.push('</a>');
						html.push('</div>');
						html.push('<div class="social-feed-box" id="'+id+'-social-feed-box-info">');
						html.push('<div class="pull-right"  style="margin-top:15px;margin-right:15px;" >');
		                html.push('<a href="javascript:;" class="btn btn-outline btn-xs btn-primary" data-id="'+id+'" data-answers-id="'+discusses.id+'" data-answers-user-id="'+discusses.createUser+'" onclick="insertQunestionHtml(this,\'-info\')" style="margin-left:5px;">修改</a>');
		                html.push('<a href="javascript:;"  class="btn btn-outline btn-xs btn-primary" onclick="deleteDiscuss(this,1)" data-discusses-id="'+discusses.id+'" data-url="${ctx}/discuss/delete"  style="margin-left:5px;">删除</a>');
		                html.push('<a href="javascript:;"  class="btn btn-outline btn-xs btn-primary" data-id="'+id+'" data-answers-id="'+discusses.id+'" data-answers-user-id="'+discusses.createUser+'" onclick="insertAnswerHtml(this)" style="margin-left:5px;">评论</a>');
		                html.push('<a href="javascript:;"  class="btn btn-outline btn-xs btn-primary" style="margin-left:5px;" onclick="clickDiscussInfoGet(this)" data-id="'+id+'">详情</a>');
		                html.push('</div>');
						html.push('<div class="social-avatar">');
						html.push('<a  href="javascript:;" >'+discusses.createUsername+'</a>');
						html.push('<span style="margin-left:10px;" class="text-muted">'+discusses.categoryName+'</span>');
						html.push('<span style="margin-left:10px;"  data-type="datetime"class="text-muted">'+discusses.createTime+'</span>');
						html.push('</div>');
						html.push('<div id="'+id+'-social-body-info" class="social-body">');
						html.push('<p>'+discusses.content+'</p>');
						
						if(discusses.img){
							var imgs=[];
							if(discusses.img.indexOf("|")>=0){
								imgs=discusses.img.split("|");
							}else{
								imgs.push(discusses.img);
							}
							html.push('<div class="photos">');
							for(var i=0;i<imgs.length;i++){
								html.push('<a target="_blank" href="'+imgs[i]+'">');
					            html.push('<img alt="image" class="feed-photo" src="'+imgs[i]+'">');
					            html.push('</a>');
							}
			                html.push('</div>');
						}
						html.push('</div>');
						
						html.push('<div id="'+id+'-social-footer-info" class="social-footer">');
			            for(var i=0;i<answers.length;i++){
			            	var row=answers[i];
			            	
			            	var row=answers[i];
			            	html.push('<div class="social-comment" id="'+row.id+'-social-comment-info">');
			                html.push('<a href="" class="pull-left">');
			                html.push('<img alt="image" src="'+row.createHeadImg+'">');
			                html.push('</a>');
			                html.push('<div class="media-body">');
			                html.push('<a  href="javascript:;" >'+row.createUsername+'</a>')
			                if(row.type==1){
			                	html.push('<a style="color:red;" href="javascript:;" >(管理用户)</a>');
			                };
			                if(row.replyUsername){
			                	 html.push('<span style="margin-left:5px;">回复</span>');
			                	 html.push('<a  href="javascript:;"  style="margin-left:5px;">'+row.replyUsername+'</a>');
			                }
			                html.push('<div class="pull-right">');
			                html.push('<a  href="javascript:;"  onclick="deleteDiscuss(this,2)" data-url="${ctx}/discuss/deleteAnswers" data-id="'+row.id+'"  data-answers-id="'+row.id+'" data-answers-user-id="'+row.createUser+'" class="btn btn-outline btn-xs btn-primary" >删除</a>');
			                html.push('<a  href="javascript:;"  onclick="insertReplyHtml(this)" data-id="'+row.id+'" style="margin-left:3px;" data-answers-id="'+row.id+'" data-answers-user-id="'+row.createUser+'" class="btn btn-outline btn-xs btn-primary">回复</a>');
			                if(!discusses.pretyAnswer){
			                	html.push('<a  href="javascript:;"  data-discuss-id="'+id+'" data-id="'+row.id+'" onclick="updatePrettyAnswer(this)" style="margin-left:3px;" data-answers-id="'+row.id+'" data-answers-user-id="'+row.createUser+'" class="btn btn-outline btn-xs btn-primary prety-answer">最佳答案</a>');
			                }
			                html.push('</div>');
			                html.push('<span style="margin-left:10px;">');
			                html.push( row.content);
			                html.push('</span>');
			                html.push('<br/>');
			                html.push('<div data-id="'+row.id+'" id="'+id+'-prety-answer">');
			                html.push('<a href="javascript:;" '+row.upUserClick?"":"disabled='disabled'"+' onclick="updateAnswers(this,1)" data-id="'+row.id+'" class="small" data-persent="1" data-num="'+row.upClick+'"  ><i class="fa fa-thumbs-up"></i>'+row.upClick+'</a>');
			                html.push('<a href="javascript:;" '+row.upUserClick?"":"disabled='disabled'"+' onclick="updateAnswers(this,2)" data-id="'+row.id+'" style="margin-left:10px" class="small" data-persent="1" data-num="'+row.downClick+'"><i class="fa fa-thumbs-down"></i>'+row.downClick+'</a>');
			                if(discusses.pretyAnswer==row.id){
			                	html.push('<a style="margin-left:10px"  href="javascript:;"  class="small">最佳答案</a>');
			                }
			                html.push('<span class="text-muted"  style="margin-left:10px"  data-type="datetime">'+row.createTime+'</span>');
			                html.push('</div>');
			                html.push('</div>');
			                html.push('</div>');
			            }
			            html.push('</div></div>');
			            $("#discuss-info").html(html.join(""));
			            
			            dataFormater("#discuss-info");
			            
					}else{
					    $.confirm({cancelButton: "关   闭",title: '提示!',content: "添加货咖说错误!"});
					}
				}  
		    }); 
		}
	
		$(function(){
		
			jQuery.searchFormInit();
			
			$("#discuss_table_search").on("click",function() {
	            retrieveData();
	        });
			
			retrieveData();
		
		});
	</script>
	
	</body>
</html>